'use strict'

const Controller = require('egg').Controller

class HomeController extends Controller {
  //数据
  async orderList() {
    const { ctx } = this
    const list = await this.app.mysql.select('order')
    ctx.body = {
      code: 200,
      msg: '订单管理数据请求成功',
      list,
    }
  }

  //删除
  async orderdel() {
    const { ctx } = this
    const { id } = ctx.query
    const res = await this.app.mysql.delete('order', { id })
    if (res.affectedRows === 1) {
      const list = await this.app.mysql.select('order')
      ctx.body = {
        code: 200,
        msg: '删除成功',
        list,
      }
    } else {
      ctx.body = {
        code: 400,
        msg: '删除失败',
        list,
      }
    }
  }

  //详情页
  async orderDetail() {
    const { ctx } = this
    const { id } = ctx.query
    console.log(id)
    const list = await this.app.mysql.get('order', { id })
    ctx.body = {
      code: 200,
      msg: '成功跳到详情页',
      list,
    }
  }
}

module.exports = HomeController
